var util = require("../../../utils/util.js");
var api = require('../../../config/api.js');
//获取应用实例
var app = getApp()

Page({
  data: {
    id: null, //预约培训id
    is_default: 0,
    coachName: "请选择教练",
    coachId: 0,
    one_2: 5,
    two_2: 0,
    navbar_bgcolor: wx.getStorageSync('navbar_bgcolor'),
    userName: ''
  },

  onLoad: function (e) {
    var that = this;
    var id = e.id != null ? e.id : null;
    var coachName = e.coachName != null ? e.coachName : "";
    var userName = e.userName != null ? e.userName : '';
    that.setData({
      id: id,
      coachName: coachName,
      userName: userName
    });
  },
  in_xin: function (e) {
    var in_xin = e.currentTarget.dataset.in;
    var one_2;
    if (in_xin === 'use_sc2') {
      one_2 = Number(e.currentTarget.id);
    } else {
      one_2 = Number(e.currentTarget.id) + this.data.one_2;
    }
    this.setData({
      one_2: one_2,
      two_2: 5 - one_2
    })
  },
  bindCancel: function () {
    wx.navigateBack({})
  },
  bindCoachEvalSave: function (e) {
    var that = this;
    var content = e.detail.value.content;

    if (content == "") {
      wx.showModal({
        title: '提示',
        content: '请填写评价内容',
        showCancel: false
      })
      return
    }
    
    var userid = wx.getStorageSync("userid");
    if(userid == ''){
      wx.navigateTo({
        url: "/pages/auth/login/login"
      });
      return;
    }
    util.request(api.CoachEval, {
      appointmentId:that.data.id,
      starRating: that.data.one_2,
      content: content,
      uid:userid
    }, "POST").then(function (res) {
      if (res.errno === 0) {
        wx.showModal({
          title: '提示',
          content: '评价成功...谢谢您的合作！',
          showCancel: false,
          success(res) {
            if (res.confirm) {
              wx.switchTab({
                url: '/pages/index/index',
              })
            }
          }
        })
      }
      wx.hideLoading();
    });
  }
})